package com.sanshengshui.iot.test;

import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

public class SerDemo {

    public static void main(String[] args) {
        RedisSerializer<String> stringSerializer = new StringRedisSerializer();

        GenericJackson2JsonRedisSerializer ser = new GenericJackson2JsonRedisSerializer();

        String str = "hello";
        byte[] bytes = stringSerializer.serialize(str);
        byte[] bytes2 = ser.serialize(str);
        // 5
        System.out.println(bytes.length);
        // 7
        System.out.println(bytes2.length);
        // hello
        System.out.println(new String(bytes));
        // "hello"
        System.out.println(new String(bytes2));

        // hello
        System.out.println(stringSerializer.deserialize(bytes));
        // hello
        System.out.println(ser.deserialize(bytes2));

        try {
            System.out.println(ser.deserialize(bytes));
        }catch(Exception e){
            // org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized token 'hello': was expecting ('true', 'false' or 'null')
            System.out.println(e+"");
        }





    }
}
